package cn.com.chengmandian.bike.controller;


import cn.com.chengmandian.agent.utils.AuthUtil;
import cn.com.chengmandian.bike.dto.MemberComboRecordDto;
import cn.com.chengmandian.bike.model.EbMemberComboRecord;
import cn.com.chengmandian.bike.model.vo.MemberComboRecordVo;
import cn.com.chengmandian.bike.service.IEbMemberComboRecordService;
import cn.com.chengmandian.core.db.pojo.PageData;
import cn.com.chengmandian.core.web.pojo.AgentInfo;
import cn.com.chengmandian.core.web.pojo.AjaxResult;
import cn.com.chengmandian.core.web.utils.LocalMapUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 电单车运营系统-会员购买记录 前端控制器
 * </p>
 *
 * @author AutoGenerator
 * @since 2023-08-28
 */
@Api(tags = "会员购买记录")
@RestController
@RequestMapping("/member/combo/record")
public class EbMemberComboRecordController {

    @Autowired
    private IEbMemberComboRecordService memberComboRecordService;

    @ApiOperation("用户历史骑行卡列表")
    @GetMapping("/pages")
    public AjaxResult<PageData<EbMemberComboRecord>> pages(MemberComboRecordDto dto) {
        AgentInfo agentInfo = LocalMapUtil.getAgentInfo();
        Assert.notNull(agentInfo.getAreaId(), "缺少运营区ID");
        dto.setAreaId(agentInfo.getAreaId());
        return AjaxResult.success(PageData.build(memberComboRecordService.pages(dto, AuthUtil.getAgentUser().getId())));
    }

    @ApiOperation("用户生效中会员卡信息")
    @GetMapping("/take/effect")
    public AjaxResult<MemberComboRecordVo> takeEffect(){
        return AjaxResult.success(memberComboRecordService.getMemberAvailableRecord(LocalMapUtil.getAgentInfo().getAreaId(), AuthUtil.getAgentUser().getId()));
    }
}
